package jvm

/**
 * @Author: DRevelation
 * @Date: 2021/9/23 14:42
 */

fun main() {
    val mutableList = mutableListOf(1, 2, 3, 4)
    val list1 = mutableList
    val list = listOf(1, 2, 3, 4)

    list.forEach { i ->
        println("$i")
    }

    val mutableMap = mutableMapOf(1 to 100, 2 to 200, 3 to 300, 4 to 400)
    mutableMap.forEach { (k, v) ->
        println("$k: $v")
    }

    //Java Integer -128~127缓存问题?
    val a: Int = 100
    val boxedA: Int? = a
    val anotherBoxedA: Int? = a

    val b: Int = 10000
    val boxedB: Int? = b
    val anotherBoxedB: Int? = b

    println(boxedA === anotherBoxedA)
    println(boxedB === anotherBoxedB)

    val asc = Array(5) { i -> (i * i).toString() }
    asc.forEach { print("$it ") }

    println()
    val text = """
    |Tell me and I forget.
    |Teach me and I remember.
    |Involve me and I learn.
    |(Benjamin Franklin)
    """.trimMargin(">")
    println(text)

    val price = """
        ${'$'}9.99
    """.trimMargin()
    println("price=${price}")

    when (val x = 127) {
        1 -> println("x==1")
        2 -> println("x==2")
        else -> println("x=$x")
    }
}